package com.marvels.financial.funds.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.financial.funds.dto.FundDTO;
import com.marvels.financial.loan.service.impl.FundServiceImpl;

/**资金源管理
 * @author 毛小宁
 * @date 2018年4月10日
 */
@RestController
@RequestMapping("/financial/fund/service")
public class FundController {
	@Autowired
	private FundServiceImpl fundService;

	/**查询资金源
	 * @author 娄凯琦
	 * @date 2018年4月19日  
	 * @param ptDto
	 * @return
	 */
	@RequestMapping("list")
	public MarvelsResultDTO searchFundSource(@RequestBody(required = false) FundDTO ptDto) {
		try {
			MarvelsLogUtil.getInstance().info("listCMPT>>>>>>>>>>>>=="+ptDto);
			List<FundDTO> pts = fundService.findFundDTO(ptDto);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pts);
		}catch(MarvelsBusinessException e){
			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(),e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
		}

	}
	
	/**增删改资金源
	 * @author 娄凯琦
	 * @date 2018年4月19日  
	 * @param ptDto
	 * @return
	 */
	@RequestMapping("addFundSource")
	public MarvelsResultDTO addFundSource(@RequestBody(required = false) FundDTO ptDto) {
		try {
			MarvelsLogUtil.getInstance().info("addFundSource>>>>>>>>>>>>=="+ptDto);
			fundService.addFund(ptDto);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),"操作成功");
		}catch(MarvelsBusinessException e){
			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(),e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
		}

	}
	
	/**查询资金源银行和限额
	 * @author 娄凯琦
	 * @date 2018年4月19日  
	 * @param ptDto
	 * @return
	 */
	@RequestMapping("searchBankAndLimit")
	public MarvelsResultDTO searchBankAndLimit(@RequestBody(required = false) FundDTO ptDto){
		try {
			MarvelsLogUtil.getInstance().info("searchBankAndLimit>>>>>>>>>>>>=="+ptDto);
			FundDTO fundDTO = fundService.queryBankAndLimit(ptDto);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),fundDTO);
		}catch(MarvelsBusinessException e){
			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(),e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
		}

	}
	
	
//	@RequestMapping("test")
//	public MarvelsResultDTO test(){
//		try {
//			LoanAfterInfoDTO loanAfterInfo = new LoanAfterInfoDTO();
//			BigDecimal amount = new BigDecimal(1111);
//			loanAfterInfo.setAmount((amount));
//			loanAfterInfo.setCustCardNo("123213");
//			loanAfterInfo.setCustName("章节");
//			loanAfterInfo.setDate(new Date());
//			loanAfterInfo.setLoanId("123455555");
//			loanAfterInfo.setFundSource("1111");
//			loanAfterInfo.setProductCode("PT906bdbff5f294526bd38408726804e08");
//			loanAfterInfo.setTenor(12);
//			loanAfterInfo.setChannelCode("101");
//			loanAfterInfo.setChannelName("线上渠道");
//			iLoanAfterInfoApi.loanApplySuccess(loanAfterInfo);
//			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),null);
//		}catch(MarvelsBusinessException e){
//			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
//			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(),e.getMessage());
//		}catch (Exception e) {
//			MarvelsLogUtil.getInstance().error("error...", e);
//			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
//		}
//
//	}
	
}
